// Boost.STL2 library
//
//  Copyright Fernando Pelliccioni 2012.
//  Use, modification and distribution is subject to the Boost Software
//  License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
//  http://www.boost.org/LICENSE_1_0.txt)
//
// For more information, see http://www.boost.org/libs/range/
//

#ifndef iterator_range_HPP__
#define iterator_range_HPP__

#include <iterator>

//TODO: Iterator Category / Constraints

//TODO: cambiar el It por T
//      Iterador es un concepto que solo deberia aparecer por compatibilidad hacia atras.


#include <iterator>



//from Boost Iterator iterator_traits.hpp
//TODO: pasar a clase especial
template <class Iterator>
struct iterator_value
{
	//typedef typename boost::detail::iterator_traits<Iterator>::value_type type;
	typedef typename std::iterator_traits<Iterator>::value_type type;
};

template <class Iterator>
struct iterator_reference
{
	//typedef typename boost::detail::iterator_traits<Iterator>::reference type;
	typedef typename std::iterator_traits<Iterator>::reference type;
};




//TODO: Iterator Category / Constraints

template <typename It>	
struct iterator_range
{
	//Old style traits
	//typedef	typename std::iterator_traits<It>::value_type value_type;
	//typedef	typename std::iterator_traits<It>::value_type reference;
	
	typedef typename iterator_value<It>::type value_type;
	typedef typename iterator_reference<It>::type reference;



	iterator_range( It begin, It end )
		: begin_(begin), end_(end)
	{}

	bool empty() const
	{
		return begin_ >= end_;
	}

	void pop_front()
	{
		++begin_;
	}

	void pop_back()
	{
		--end_;
	}

	reference front() const
	{
		return *begin_;
	}

	reference back() const
	{
		//BOOST_ASSERT( !empty() );

		It last(end_);
		return *--last;
		//return *(end_-1);
	}

private:

	It begin_;
	It end_;

};



#endif // iterator_range_HPP__